from django.db import models


class Menu(models.Model):
    """
    菜单
    """
    name = models.CharField(max_length=32, unique=True, verbose_name='菜单名称')
    level = models.IntegerField(default=0, verbose_name='菜单等级')
    path = models.CharField(max_length=32, null=True, blank=True, verbose_name='菜单路径')
    scopes = models.CharField(max_length=32, null=True, blank=True, verbose_name='菜单权限')
    is_menu = models.BooleanField(default=True, verbose_name='是否为菜单')
    pid = models.ForeignKey('self', related_name='children', null=True, blank=True, on_delete=models.CASCADE,
                            verbose_name='父级菜单Id')
    roles = models.ManyToManyField('roles.Role', related_name='menus', blank=True, verbose_name='角色')

    class Meta:
        db_table = 'menu'
        db_table_comment = '菜单表'
        verbose_name = '菜单'
        verbose_name_plural = verbose_name
